package com.bzkj.web.controller.warehouse;

import com.bzkj.basicinfo.domain.warehouse.PdaWarehouseInBillsDetail;
import com.bzkj.basicinfo.domain.warehouse.PdaWarehouseInBillsList;
import com.bzkj.basicinfo.service.warehouse.IPdaWarehouseInBillsService;
import com.bzkj.common.annotation.LogB;
import com.bzkj.common.core.controller.BaseController;
import com.bzkj.common.core.domain.AjaxResult;
import com.bzkj.common.core.page.TableDataInfo;
import com.bzkj.common.enums.BusinessType;
import com.bzkj.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * PDA入库单据管理Controller - 统一入库流程
 *
 * @author system
 * @date 2025-10-23
 */
@RestController
@RequestMapping("/warehouse/pda/inbound")
public class PdaWarehouseInController extends BaseController {

    @Autowired
    private IPdaWarehouseInBillsService pdaWarehouseInBillsService;

    /**
     * 查询入库单据列表
     */
    @PreAuthorize("@ss.hasPermi('warehouse:pda:list')")
    @GetMapping("/list")
    public TableDataInfo list(PdaWarehouseInBillsList billsList) {
        startPage();
        List<PdaWarehouseInBillsList> list = pdaWarehouseInBillsService.selectPdaWarehouseInBillsList(billsList);
        return getDataTable(list);
    }

    /**
     * 新增入库单据
     */
    @PreAuthorize("@ss.hasPermi('warehouse:pda:add')")
    @LogB(title = "新增入库单据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PdaWarehouseInBillsList billsList) {
        return toAjax(pdaWarehouseInBillsService.insertPdaWarehouseInBillsList(billsList));
    }

    /**
     * 修改入库单据
     */
    @PreAuthorize("@ss.hasPermi('warehouse:pda:edit')")
    @LogB(title = "修改入库单据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PdaWarehouseInBillsList billsList) {
        return toAjax(pdaWarehouseInBillsService.updatePdaWarehouseInBillsList(billsList));
    }

    /**
     * 删除入库单据
     */
    @PreAuthorize("@ss.hasPermi('warehouse:pda:remove')")
    @LogB(title = "删除入库单据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{billsIds}")
    public AjaxResult remove(@PathVariable String[] billsIds) {
        return toAjax(pdaWarehouseInBillsService.deletePdaWarehouseInBillsByBillsIDs(billsIds));
    }

    // ========== 验收相关接口 ==========

    /**
     * 查询待验收的单据列表（状态=1）
     */
    @PreAuthorize("@ss.hasPermi('warehouse:pda:inspect:list')")
    @GetMapping("/inspect/pending")
    public TableDataInfo getPendingInspect(PdaWarehouseInBillsList billsList) {
        startPage();
        List<PdaWarehouseInBillsList> list = pdaWarehouseInBillsService.selectPendingInspectList(billsList);
        return getDataTable(list);
    }

}
